package com.stedu.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class AdminInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        //获取Session
        HttpSession session = request.getSession();
        //判断session中是否保存了已登录用户信息
        Object admin = session.getAttribute("admin");
        if (admin != null) {
            return true;
        } else {

            response.sendRedirect(request.getContextPath() + "/toLogin");
            return false;
        }
    }
}
